import Vue from 'vue';
import Vuex from 'vuex';

import getters from './getters';

import {
	synchroUserinfo,enums
} from '@/api/equip.js';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		userinfo: {},
		enums: {},
	},
	mutations: {
		setUserInfo(state, userinfo) {
			state.userinfo = userinfo;
		},
		SET_ENUMS: (state, enums) => {
			state.enums = enums
		},
	},
	actions: {
		updateUserInfo: ({
			commit,
			state
		}) => {
			synchroUserinfo('/all', 'post').then(res => {
				commit("setUserInfo", res.data)
			})
		},
		enums({
			commit
		}) {
			return new Promise((resolve, reject) => {
				enums('/all','post').then((response) => {
					const {
						data
					} = response;
					commit('SET_ENUMS', data);
					resolve()
				}).catch(error => {
					reject(error)
				})
			})
		},
	},
	getters,
})
